<template>
  <div>
    <ul>
      <li v-for="(item, index) in products" :key="index">
        {{ item.title }}-{{ item.price }}--{{ item.inventory }}
        <button :disabled="!item.inventory" @click="addCar(item)">
          加入购物车
        </button>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions("shop", ["getData", "addCar"]),
    ...mapActions("car", ["addCar"]),
  },
  computed: {
    ...mapState("shop", ["products"]),
  },
  mounted() {
    this.getData();
  },
};
</script>

<style scoped></style>
